<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>合作连接信息管理</title>
		<link rel="stylesheet" type="text/css" href="../res/easyui/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../res/easyui/themes/color.css">
		<link rel="stylesheet" type="text/css" href="../res/easyui/themes/icon.css">
		<script type="text/javascript" src="../res/js/jquery-1.12.3.min.js"></script>
		<script type="text/javascript" src="../res/easyui/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../res/easyui/locale/easyui-lang-zh_CN.js"></script>
		<style>
			#data_dialog table input[type=text]{
				width: 225px;
			}
			#data_dialog table textarea{
				width: 225px;
				resize: none;
				height: 60px;
			}
			#data_dialog table .ltd{
				text-align: left;
				padding-right: 10px;
			}
			#data_dialog table .rtd{
				text-align: right;
			}
			#data_dialog table td{
				padding: 5px 0;
			}
			.e_d_file_box {
				float: left;
				height: 30px;
				background: #00EE00;
				width: 140px;
				position: relative;
				cursor: pointer;
			}
			
			.e_d_file_div {
				text-align: center;
				font-size: 15px;
				height: 30px;
				line-height: 30px;
			}
			
			.e_d_file_input {
				width: 140px;
				height: 30px;
				cursor: pointer;
				font-size: 30px;
				outline: medium none;
				position: absolute;
				filter: alpha(opacity=0);
				-moz-opacity: 0;
				opacity: 0;
				left: 0px;
				top: 0px;
			}
		</style>
	</head>
	<body>
		<!--表格的工具栏-->
		<div id="exchange_dg_tb" style="padding:5px;height:auto">
			<div style="margin-bottom:5px;">
				<a href="javascript:openDialog();" class="easyui-linkbutton" iconCls="icon-add"  title="添加" plain="true">添加</a>
				<a href="javascript:updateDialog();" class="easyui-linkbutton" iconCls="icon-edit"  title="修改" plain="true">修改</a>
				<a href="javascript:deleteDialog();" class="easyui-linkbutton" iconCls="icon-remove" title="删除" plain="true">删除</a>
			</div>
			<div>
				<label for="q_type">类型:</label> 
				<select id="q_type" class="easyui-combobox" panelHeight="auto" style="width:100px">
					<option value="-1">全部</option>
					<option value="1">交易所</option>
					<option value="2">媒体类</option>
				</select>
				<label for="q_name">名称:</label><input id="q_name" type="text"/>
				<a href="javascript:searchData();" class="easyui-linkbutton" iconCls="icon-search">搜索</a>
			</div>
		</div>
		<!--表格的工具栏 结束-->
		<!--表格数据-->
		<table id="data_dg" class="easyui-datagrid" title="合作连接信息"
			data-options="singleSelect:true, method:'get',url:'json/hezuo_1.json', fit:true, pagination:true, toolbar:'#exchange_dg_tb'">
			<thead>
				<tr>
					<th data-options="field:'ck',checkbox:true"></th>
					<th data-options="field:'id',hidden:true">ID</th>
					<th data-options="field:'type',width:100, align:'center', formatter:formatterType">类型</th>
					<th data-options="field:'name',width:440">名称</th>
					<th data-options="field:'url',width:500">网址</th>
					<th data-options="field:'pdate',width:130,align:'center'">时间</th>
				</tr>
			</thead>
		</table>
		<!--表格数据 结束-->
		
		<!--编辑区域-->
		<div id="data_dialog" class="easyui-dialog" title="合作连接信息对话框" style="height:130px; width: 600px; padding: 10px;"  
		        data-options="iconCls:'icon-save',resizable:false,modal:true, closed:true, maximized:false">  
		        <input type="hidden" name="e_id" id="e_id" value="" />
		    <table border="0" cellspacing="0" cellpadding="0">
		    	<tr>
		    		<td class="rtd">名称：</td>
		    		<td class="ltd"><input type="text" name="title" id="e_name" value="" style="width: 200px;" /></td>
		    		<td class="rtd">网址：</td>
		    		<td class="ltd"><input type="text" name="title" id="e_url" value="http://" style="width: 200px;" /></td>
		    	</tr>
		    	
		    	<tr>
		    		<td class="rtd"><label for="e_type">类型:</label></td>
		    		<td>
		    			<select id="e_type" class="easyui-combobox" panelHeight="auto" style="width:100px">
							<option value="1">交易所</option>
							<option value="2">媒体类</option>
						</select>
		    		</td>
		    		
		    		<td colspan="2">
		    			<input type="button" id="" value="提交" />
		    		</td>
		    	</tr>
		    </table>
		</div>
		<!--编辑区域  结束-->
	</body>
	
	<script type="text/javascript">
		$(function(){
		});
		
		// 获取时间 yyyy-MM-dd HH:mm:ss
		function getDateTime(showSeconds){  
			var _date = new Date();
            var y = _date.getFullYear();  
            var m = _date.getMonth()+1;  
            var d = _date.getDate();  
            var dateStr = y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
            if(showSeconds){
            	var h = _date.getHours();
	            var min = _date.getMinutes();  
	            var sec = _date.getSeconds();
	            var timeStr = (h<10?('0'+h):h)+':'+(min<10?('0'+min):min)+':'+(sec<10?('0'+sec):sec); 
	            return dateStr + " " + timeStr;
            }
            return dateStr + " 00:00:00";  
        }  
		
		// 点击查询数据
		function searchData(){
			$("#data_dg").datagrid({
				url:"load.do",
				queryParams: {
					name: $('#q_name').datetimebox('getValue'),
					type: $('#q_type').combobox('getValue')
				}
			});
		}
		
		// 格式化type
		function formatterType(value,row,index){
			if(value == 1){
				return "交易所";
			}else if(value == 2){
				return "媒体类";
			}
			return "未知";
		}
		
		// 打开添加对话框
		function openDialog(){
			$("#e_id").val("");
			$("#e_name").val("");
			$("#e_url").val("");
			$("#e_type").combobox("setValue", 1);
			
			$("#data_dialog").dialog("open");
		}
		
		
		// 点击修改
		function updateDialog(){
			var row = $("#data_dg").datagrid("getSelected");
			if(row == null){
				alert("请先选中一条要编辑的数据");
				return;
			}
			$("#e_id").val(row.id);
			$("#e_name").val(row.name);
			$("#e_url").val(row.url);
			$("#e_type").combobox("setValue", row.type);
			
			$("#data_dialog").dialog("open");
		}
		
		// 删除一行数据
		function deleteDialog(){
			var row = $("#data_dg").datagrid("getSelected");
			if(row == null){
				alert("请先选中一条要删除的数据");
				return;
			}
			$.messager.confirm('确认对话框','你确定要删除此行数据吗?删除后无法恢复！',function(r){   
			    if (r){   
			        $.ajax({
			        	type:"post",
			        	url:"delete.do",
			        	data:{"id":row.id},
			        	async:true,
			        	success:function(result){
			        		alert(result.msg);
			        		if(result.status == 1){
			        			var index = $("#data_dg").datagrid("getRowIndex", row);
								$("#data_dg").datagrid("deleteRow", index);
							}
			        	}
			        });  
			    }   
			});  
		}
		// 点击提交信息
		function submitInfo(){
			var _id = $("#e_id").val();
			var _name = $("#e_name").val();
			var _url = $("#e_url").val();
			var _type = $("#e_type").combobox("getValue");
			var submitUrl = "add.do";
			if(_id != ""){
				submitUrl = "update.do";
			}
			$.ajax({
				type:"post",
				url: submitUrl,
				async:true,
				data:{"id":_id, "name":_name, "url":_url, "type":_type},
				success:function(result){
					alert(result.msg);
					$('#data_dialog').dialog('close');
					if(result.status == 1){
						$("#data_dg").datagrid("reload");
					}
				}
			});
		}
	</script>
	
</html>
